<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <title>购物车</title>
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/dialog.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <script src="../js/flexible.js" type="text/javascript"></script>
    <script src="../js/swiper.min.js" type="text/javascript"></script>
    <script src="../js/zepto-v1.2.0.min.js" type="text/javascript"></script>
    <script src="../js/dialog.min.js" type="text/javascript"></script>
  </head>
  <body>
    <div class="shopping-cart-wrapper common-wrapper">
      <header class="header-wrapper clearfix">
        <div class="header-container white-background">
          <div class="left-container">
            <a class="back black-back" href="javascript:history.back(-1)"></a>
          </div>
          <span class="title">购物车</span>
          <div class="right-container">
            <a class="edit">编辑</a>
          </div>
        </div>
      </header>
      <section class="cart-goods-list">
        <div class="goods-item clearfix">
          <span class="checkbox checked"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox checked"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox checked"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
        <div class="goods-item clearfix">
          <span class="checkbox"></span>
          <img src="../img/1x/goods-plane3.png" />
          <div class="goods-info">
            <div class="title text-overflow">C919航模</div>
            <div class="desc">DA-40型号</div>
            <div class="price-wrapper">
              <span class="price-item"><i class="num">￥320 </i>/件</span>
            </div>
          </div>
          <div class="counter">
            <span class="minus">-</span>
            <span class="count">1</span>
            <span class="add">+</span>
          </div>
        </div>
      </section>
      <div class="settlement-wrapper">
        <span class="checkall">
          <span class="checkbox"></span>
          全选
        </span>
        <div class="settlement-container">
          <div class="settlement-info">
            <span class="desc">不含运费</span>
            <span class="summary"> 合计：<span class="total">¥640</span> </span>
          </div>
          <a class="normal-btn primary-btn" href="submitOrder.html">结算(2)</a>
        </div>
        <div class="delete-container">
          <a class="normal-btn delete">删除</a>
        </div>
      </div>
      <footer class="nav-wrapper">
        <a class="nav-item home" href="home.html">
          <div class="icon"></div>
          <div class="title">首页</div>
        </a>
        <a class="nav-item search">
          <div class="icon"></div>
          <div class="title">信息查询</div>
        </a>
        <a class="nav-item shopping-cart active" href="shoppingCart.html">
          <div class="icon"></div>
          <div class="title">购物车</div>
        </a>
        <a class="nav-item mine">
          <div class="icon"></div>
          <div class="title">我的</div>
        </a>
      </footer>
    </div>
  </body>
  <script src="../js/footerNav.js"></script>
  <script>
    $(document).ready(function () {
      var mySwiper = new Swiper('.swiper-container', {
        loop: true,
        autoplay: true,
        pagination: {
          el: '.swiper-pagination',
        },
      })
      $('.tab-item').click(function () {
        $(this).addClass('active').siblings().removeClass('active')
      })
      const disabledFunc = (currentCount) => {
        if (currentCount === 1) {
          $('.minus').addClass('disabled')
        } else {
          $('.minus').removeClass('disabled')
        }
      }
      disabledFunc()
      $('.add').click(function (e) {
        const currentCountEle = $(this).prev()[0]
        let currentCount = Number(currentCountEle.innerHTML)
        currentCount += 1
        $(currentCountEle).html(currentCount)
        disabledFunc(currentCount)
      })
      $('.minus').click(function () {
        const currentCountEle = $(this).next()[0]
        let currentCount = Number(currentCountEle.innerHTML)
        currentCount -= 1
        $(currentCountEle).html(currentCount)
        disabledFunc(currentCount)
      })
      $('.checkbox')
        .not('.checkall .checkbox')
        .click(function () {
          $(this).toggleClass('checked')
          const checkboxes = $('.checkbox').not('.checkall .checkbox')
          const checkedboxes = checkboxes.filter('.checked')
          if (checkboxes.length === checkedboxes.length) {
            $('.checkall .checkbox').addClass('checked')
          } else {
            $('.checkall .checkbox').removeClass('checked')
          }
        })
      $('.checkall').click(function () {
        const checkallbox = $(this).children('.checkbox')
        const checkboxes = $('.checkbox').not(checkallbox)
        const isCheckedAll = $(this).children('.checkbox').hasClass('checked')
        if (isCheckedAll) {
          checkboxes.removeClass('checked')
          checkallbox.removeClass('checked')
        } else {
          checkboxes.addClass('checked')
          checkallbox.addClass('checked')
        }
      })
      $('.edit').click(function () {
        let status = $(this).html() === '编辑' ? 'edit' : 'delete'
        if (status === 'edit') {
          status = 'delete'
          $(this).html('完成')
          $('.settlement-container').hide()
          $('.delete-container').show()
        } else {
          status = 'edit'
          $(this).html('编辑')
          $('.settlement-container').show()
          $('.delete-container').hide()
        }
      })
      $('.delete').click(function () {
        $(document).dialog({
          type: 'confirm',
          titleShow: false,
          content: '您确定要删除商品吗？',
          buttonTextConfirm: '确定',
          buttonTextCancel: '取消',
          buttonClassConfirm: 'delete-confirm',
          buttonClassCancel: 'delete-cancel',
          onClickConfirmBtn: function () {
            alert('你点了“确定”按钮')
          },
          onClickCancelBtn: function () {
            alert('你点了“取消”按钮')
          },
        })
      })
    })
  </script>
</html>
